import importlib

def exec_task(task_name,*args):
    if not task_name:
        return -1, "task name must not None"
    try:
        module_name = task_name.rsplit(".", 1)[0]
        method_name = task_name.rsplit(".", 1)[1]
        
        # 动态导入tasks模块(__import__的module_obj似乎仅表示最外部的module)
        # module_obj = __import__(module_name)
        # module_obj=module_obj['in_task']['in_task1']
        # 如果涉及挎包，最好的动态调用方式，是importlib.import_module
        module_obj=importlib.import_module(module_name)
        if not hasattr(module_obj, method_name):
            return -1, f"function {method_name} not found"
    except:
        return -1, "has Error"
        
    task = getattr(module_obj, method_name)
    print(task is None)
    print(type(task))
    # print(type(task.task1))
    return task(*args)

if __name__=='__main__':
    # 调用外部包
    res=exec_task('math.sqrt',2)
    print(res)


    res1=exec_task('task.in_task.in_task1.in_taskf1')
    print(res1)

    res2=exec_task('task.task2.task2')
    print(res2)
